import React from 'react'
import styles from './index.css'
import classnames from 'classnames'
class Button extends React.Component{

    constructor(props){
        super(props)
        this.state={
            loading:false
        }
        console.log("constuctor")
    }
    componentDidMount(){

    }
    handleClick(){
        if(this.props.onClick!=null){
            this.props.onClick();
        }
        this.setState({loading:true})
    }
    render(){

        /*let labelText = this.state.loading?"加载中...":this.props.labelText

        if(labelText==null){
            labelText="保存"
        }*/

        let labelText="保存"
        if(this.state.loading){
            if(this.props.labelText==null){
                labelText+='中...'
            }else{
                labelText=this.props.labelText+'中...'
            }
        }else {
            if(this.props.labelText!=null){
                labelText=this.props.labelText
            }
        }

        const element=(<div className={classnames("lui-button",this.state.loading?'lui-button-loading':'lui-button-primary')} onClick={this.handleClick.bind(this)}>
            {labelText}
        </div>)
        return element
    }

}
export default Button
